package com.example.lenovo.sbns.Activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVOSCloud;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.GetCallback;
import com.avos.avoscloud.SaveCallback;
import com.example.lenovo.sbns.R;

public class Index extends AppCompatActivity {

    private RadioGroup Group;
    private RadioButton First;
    private RadioButton Second;
    private RadioButton Third;
    private RadioButton Fourth;
    private RadioButton Fifth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        RadioGroupCheckedChangeLisitener radioGroupCheckedChangeLisitener = new RadioGroupCheckedChangeLisitener();
        Group = (RadioGroup)findViewById(R.id.Group);
        Group.setOnCheckedChangeListener(radioGroupCheckedChangeLisitener);
        First = (RadioButton) findViewById(R.id.FirstButton);
        Second = (RadioButton) findViewById(R.id.SecondButton);
        Third = (RadioButton) findViewById(R.id.ThirdButton);
        Fourth = (RadioButton) findViewById(R.id.FourthButton);
        Fifth = (RadioButton) findViewById(R.id.FifthButton);
        Third.setChecked(true);

        Drawable drawable3 = getResources().getDrawable(R.mipmap.login);
        drawable3.setBounds(0,0,100,100);
        First.setCompoundDrawables(null, drawable3, null, null);

        Drawable drawable = getResources().getDrawable(R.mipmap.yiliaoclick);
        drawable.setBounds(0, 0, 100, 100);//第一0是距左边距离，第二0是距上边距离，40分别是长宽
        Second.setCompoundDrawables(null, drawable, null, null);//只放左边

        Drawable drawable2 = getResources().getDrawable(R.mipmap.goumai);
        drawable2.setBounds(0,0,100,100);
        Third.setCompoundDrawables(null, drawable2, null, null);

        Drawable drawable4 = getResources().getDrawable(R.mipmap.quan);
        drawable4.setBounds(0,0,100,100);
        Fourth.setCompoundDrawables(null, drawable4, null, null);

        Drawable drawable5 = getResources().getDrawable(R.mipmap.tixing);
        drawable5.setBounds(0,0,100,100);
        Fifth.setCompoundDrawables(null, drawable5, null, null);



        /**
         * 测试数据库
         */
        // 初始化参数依次为 this, AppId, AppKey
        AVOSCloud.initialize(this, "Po6OudEc9QxRgv1qcussxBxi-gzGzoHsz", "EFNsW7y5aXtKMkpU50xyhHNk");
        // 测试 SDK 是否正常工作的代码
        AVObject testObject = new AVObject("TestObject");
        testObject.put("words","Hello Android!");
        testObject.saveInBackground(new SaveCallback() {
            @Override
            public void done(AVException e) {
                if (e == null) {
                    Log.d("saved", "success!");
                }
            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_index, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * RadioGroup监听器
     */
    public class RadioGroupCheckedChangeLisitener implements RadioGroup.OnCheckedChangeListener{
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId){
                case R.id.FirstButton:{
                    System.out.println('\n'+"1"+'\n');

                    themePage themePage = new themePage();
                    System.out.println("01");
                    FragmentManager fragmentManager = getFragmentManager();
                    System.out.println("02");
                    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                    System.out.println("03");
                    beginTransaction.replace(R.id.FrameOut, themePage);
                    System.out.println("04");
                    beginTransaction.commit();
                    setTitle("AAA");
                    System.out.println("05");


                    break;
                }
                case R.id.SecondButton:{
                    System.out.println('\n' + "2" + '\n');

                    classifyPage classifyPage = new classifyPage();
                    System.out.println("01");
                    FragmentManager fragmentManager = getFragmentManager();
                    System.out.println("02");
                    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                    System.out.println("03");
                    beginTransaction.replace(R.id.FrameOut, classifyPage);
                    System.out.println("04");
                    beginTransaction.commit();
                    setTitle("BBB");
                    System.out.println("05");


                    break;
                }
                case R.id.ThirdButton:{
                    System.out.println('\n'+"3"+'\n');
                    indexPage indexPage = new indexPage();
                    System.out.println("01");
                    FragmentManager fragmentManager = getFragmentManager();
                    System.out.println("02");
                    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                    System.out.println("03");
                    beginTransaction.replace(R.id.FrameOut, indexPage);
                    getActionBar();
                    System.out.println("04");
                    beginTransaction.commit();
                    setTitle("孝心购");
                    System.out.println("05");



                    break;
                }
                case R.id.FourthButton:{
                    System.out.println('\n' + "4" + '\n');

                    photoPage photoPage = new photoPage();
                    System.out.println("01");
                    FragmentManager fragmentManager = getFragmentManager();
                    System.out.println("02");
                    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                    System.out.println("03");
                    beginTransaction.replace(R.id.FrameOut, photoPage);
                    System.out.println("04");
                    beginTransaction.commit();
                    setTitle("孝心墙");
                    System.out.println("05");

                    break;
                }
                case R.id.FifthButton:{
                    System.out.println('\n'+"5"+'\n');

                    socumentPage socumentPage= new socumentPage();
                    System.out.println("01");
                    FragmentManager fragmentManager = getFragmentManager();
                    System.out.println("02");
                    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                    System.out.println("03");
                    beginTransaction.replace(R.id.FrameOut, socumentPage);
                    System.out.println("04");
                    beginTransaction.commit();
                    setTitle("EEE");
                    System.out.println("05");

                    break;
                }
            }
        }
    }

}


